// shopPages/addgenjin/addgenjin.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    content: '',
    uid: '',
    name: '',
    logo: '',
    customerListIndex:'',
    totalCount:'',
    userType:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      uid: options.uid,
      name: options.name,
      logo: options.logo,
      customerListIndex: options.index,
      totalCount: options.totalCount,
      userType: options.userType
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  inputContent: function(e) {
    console.log(e.detail.value)
    this.data.content = e.detail.value;
  },

  subGenjin: function() {
    var that = this;
    wx.request({
      url: app.globalData.bossradar +'/api/1.0/saveFollow',
      data: {
        belongUid: app.globalData.userInfo.id , //用户id
        uid: that.data.uid, //客户id
        userName: that.data.name, //客户名称
        context: that.data.content, //跟进内容
        userType: that.data.userType
      },
      method: 'POST',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log(res.data)
        if (res.data.code == '0') {
          wx.showToast({
            title: '添加成功',
          })

          var pages = getCurrentPages();
          var prePage = pages[pages.length - 2];
          var prePages = pages[pages.length - 3];
          console.log(that.data.customerListIndex)
          console.log(prePage);
          wx.navigateBack({
            success(){
              prePage.getgenjin();
              var str = 'list[' + that.data.customerListIndex +'].followNum'
              var total = parseInt(that.data.totalCount) + 1;
              console.log(total);
              prePages.setData({
                [str]: total
              })
              // prePages.data.list[customerListIndex].followNum++;
            }
          })
        }
      }
    })
  }

})